Skip to content

feat: support dropping multiple types with schema.dropType(), cascade. - #1516

Merged
igalklebanov merged 18 commits into
kysely-org:nextfrom
aantia:dropType-array
Sep 27, 2025
Merged

feat: support dropping multiple types with schema.dropType(), cascade.#1516
igalklebanov merged 18 commits into
kysely-org:nextfrom
aantia:dropType-array

Conversation

@aantia

@aantia aantia commented Jul 18, 2025

Copy link
Copy Markdown
Contributor

Closes #1508

This PR adds support for arrays as input to the schema.dropType() method, e.g.

db.schema.dropType(['species', 'colors'])

While I was in the area I also added .cascade() and .restrict() methods, to completely support Postgres' DROP TYPE. I based the implementation on the one for DropConstraintNode.

I only added functionality tests as the existing dropType() method didn't have type tests and I wasn't sure how to go about writing them.

@vercel

vercel Bot commented Jul 18, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kysely ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 23, 2025 11:21am

@pkg-pr-new

pkg-pr-new Bot commented Jul 18, 2025

Copy link
Copy Markdown

kysely_koa_example

npm i https://pkg.pr.new/kysely-org/kysely@1516

commit: 1ae6987

Comment thread src/operation-node/drop-type-node.ts Outdated
Comment thread src/operation-node/drop-type-node.ts Outdated
Comment thread src/query-compiler/default-query-compiler.ts Outdated
@igalklebanov igalklebanov added enhancement New feature or request postgres Related to PostgreSQL api Related to library's API labels Jul 18, 2025
@aantia

aantia commented Jul 19, 2025

Copy link
Copy Markdown
Contributor Author

@igalklebanov Will this work for compatibility? I've never really looked at any Kysely plugins or compilers, so I'm not quite sure what I'm doing.

@igalklebanov

igalklebanov commented Jul 19, 2025

Copy link
Copy Markdown
Member

@igalklebanov Will this work for compatibility? I've never really looked at any Kysely plugins or compilers, so I'm not quite sure what I'm doing.

It's perfectly fine to ask and not get things right the first time. I'm more than happy to help!

A library operates within an ecosystem. Public APIs are important, and smoothening transitions is something that needs to be thought about.

When you rename a property in an operation node or change the signature of the function that creates such nodes - that's a breaking change that might affect (custom) dialects (their compilers) and plugins, potentially making them unuseable with the next version of this library.

Currently, the ecosystem knows of name, and that it always exists. Let's not break that promise.
It also knows that in order to create a DropTypeNode you provide a single name as the first argument. Let's not break that promise.

What we can do:

  1. Keep node.name, untouched. It will represent the leading type name in the query. This ensures downstream code that accesses node.name doesn't break.
  2. Add node.additionalNames?: SchemableIdentifierNode[]. It will represent any other type names (excluding the leading type name). The cost is slighly more complex compilation code, and it's a price we're willing to pay.
  3. Add a second additionalNames?: SchemableIdentifierNode[] argument in DropTypeNode.create, leaving the first function argument (name) untouched. The cost is a slice operation before invoking DropTypeNode.create, and it's a price we're willing to pay. OR, turn the first argument into a SchemableIdentifierNode | SchemableIdentifierNode[] union, and handle both cases within the creation logic.

@aantia

aantia commented Jul 20, 2025

Copy link
Copy Markdown
Contributor Author

This should now be ready for re-review. Thanks for the help :)

Comment thread src/operation-node/drop-type-node.ts Outdated
Comment thread src/query-compiler/default-query-compiler.ts Outdated
Comment thread src/parser/identifier-parser.ts Outdated
Comment thread src/schema/schema.ts Outdated
@igalklebanov igalklebanov changed the title Support dropping multiple types with schema.dropType(), cascade/restrict. Support dropping multiple types with schema.dropType(), cascade. Sep 27, 2025

@igalklebanov igalklebanov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed .restrict() to align with drop view.
Applied my suggestions.
Ran formatter.

@igalklebanov
igalklebanov merged commit 76e5d61 into kysely-org:next Sep 27, 2025
27 of 29 checks passed
@igalklebanov igalklebanov mentioned this pull request Sep 27, 2025
igalklebanov added a commit that referenced this pull request Sep 28, 2025
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Sep 29, 2025
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Oct 9, 2025
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Oct 9, 2025
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Oct 11, 2025
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Dec 13, 2025
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Dec 14, 2025
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Dec 21, 2025
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Dec 21, 2025
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Jan 17, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Jan 17, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Jan 17, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Jan 17, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Jan 18, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Feb 1, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Feb 8, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Mar 20, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Apr 2, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Apr 4, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Apr 4, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Apr 10, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request Apr 12, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
@igalklebanov igalklebanov changed the title Support dropping multiple types with schema.dropType(), cascade. feat: support dropping multiple types with schema.dropType(), cascade. Apr 24, 2026
igalklebanov added a commit that referenced this pull request May 7, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
igalklebanov added a commit that referenced this pull request May 8, 2026
Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to library's API enhancement New feature or request postgres Related to PostgreSQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support an array as input for schema.dropType()

2 participants